<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      :isHaveExport="false"
      @toAdd="add_data"
      :searchData="userSearchData"
      @sendUserSearch="receive_search"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.ava)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="人才信息" min-width="150">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>姓名：</span>
                  <span>{{ scope.row.name }}</span>
                </div>
                <div>
                  <span>年龄：</span>
                  <span>{{ scope.row.age }}</span>
                </div>
                <div>
                  <span>经验：</span>
                  <span>{{ scope.row.jingyan }}</span>
                </div>
                <div>
                  <span>标签：</span>
                  <span>{{ scope.row.lable }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="领域" min-width="150">
            <template slot-scope="scope">
              {{ scope.row.lingyu }}
            </template>
          </el-table-column>

          <el-table-column label="时间信息" min-width="220">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>添加时间：</span>
                  <span>{{ scope.row.created_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>修改时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="editbtn(scope.row)"
                  type="primary"
                  >编辑</el-button
                >
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="danger"
                  @click="deletebtn(scope.row.id)"
                  >删除</el-button
                >
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      title="编辑"
      class="tl size_13"
      width="800px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="edit_form" ref="form" label-width="120px">
        <el-form-item label="领域：">
          <el-col :span="24">
            <el-radio-group v-model="edit_form.lingyu">
              <el-radio
                :label="item"
                v-for="(item, i) in lingyu"
                :key="i"
              ></el-radio>
              <el-radio label="自定义"></el-radio>
            </el-radio-group>
          </el-col>
          <el-col :span="6" v-if="edit_form.lingyu == '自定义'">
            <el-input
              type="text"
              clearable
              size="small"
              placeholder="自定义领域"
              v-model="lingyustr"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-col :span="18">
            <el-input
              type="text"
              clearable
              placeholder="请输入姓名"
              v-model="edit_form.name"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="头像">
          <el-col :span="18" class="tl">
            <el-input
              v-model="edit_form.ava"
              clearable
              class="mar_bottom_5"
              disabled
            ></el-input>
            <uploadpic
              :piclink="edit_form.ava"
              :width="150"
              :height="150"
              :real_width="150"
              :real_height="150"
              :is_more="false"
              @send_pic="onSuccess"
            >
            </uploadpic>
          </el-col>
        </el-form-item>

        <el-form-item label="年龄：">
          <el-col :span="18">
            <el-input
              type="text"
              clearable
              placeholder="请输入年龄"
              v-model="edit_form.age"
            >
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="经验：">
          <el-col :span="18">
            <el-input
              type="text"
              clearable
              placeholder="请输入经验"
              v-model="edit_form.jingyan"
            >
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="标签：">
          <el-col :span="18">
            <el-input
              type="text"
              clearable
              placeholder="请输入标签"
              v-model="edit_form.lable"
            >
              <span slot="append">用@隔开</span>
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="个人资料：">
          <el-col :span="18">
            <el-input
              type="textarea"
              :rows="6"
              clearable
              placeholder="请输入个人资料"
              v-model="edit_form.content"
            >
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="案例：">
          <el-row>
            <el-col
              :span="8"
              v-for="(item, i) in edit_form.piclink"
              :key="i"
              style="position: relative"
            >
              <el-image
                style="width: 150px; height: 150px"
                :src="item"
                :preview-src-list="edit_form.piclink"
              >
              </el-image>
              <i
                class="el-icon-delete"
                style="
                  position: absolute;
                  top: 10px;
                  left: 120px;
                  font-size: 20px;
                "
                @click="delPiclink(i)"
              ></i>
            </el-col>
            <el-col :span="8">
              <uploadpic
                :width="150"
                :height="150"
                :is_tip="false"
                :is_more="false"
                @send_pic="onSuccess2"
              >
              </uploadpic>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item class="tc">
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="editlive(edit_form)"
            >编 辑</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { dz_tutor_list } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import uploadpic from "@/components/page/pic/up_pic";
export default {
  data() {
    return {
      userSearchData: dz_tutor_list,
      is_edit: false,
      dialogFormVisible: false,
      edit_form: {},
      loading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      lingyu: [],
      lingyustr: "",
    };
  },
  components: {
    uploadpic,
  },
  methods: {
    delPiclink(i) {
      this.edit_form.piclink.splice(i, 1);
    },
    onSuccess2(pic) {
      this.edit_form.piclink.push(pic);
    },
    onSuccess(pic) {
      this.$set(this.edit_form, "ava", pic);
    },
    deletebtn(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getDz.del_personnel_list({ id: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data() {
      this.edit_form = {
        ava: "",
        piclink: [],
      };
      this.lingyustr = "";
      this.is_edit = false;
      this.dialogFormVisible = true;
    },
    editlive(item) {
      var params = {};
      params = JSON.parse(JSON.stringify(item));
      params.piclink = item.piclink.join("@");
      if (params.lingyu == '自定义') {
        params.lingyu = this.lingyustr;
      }
      if (this.is_edit == false) {
        this.$api.getDz.add_personnel_list(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        params.id = item.id;
        this.$api.getDz.edit_personnel_list(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn(item) {
      this.is_edit = true;
      this.edit_form = JSON.parse(JSON.stringify(item));
      this.lingyustr = "";
      if (this.edit_form.piclink) {
        this.edit_form.piclink = this.edit_form.piclink.split("@");
      } else {
        this.edit_form.piclink = [];
      }
      this.dialogFormVisible = true;
    },
    receive_search(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getDz.get_personnel_list(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
          this.lingyu = res.data.result.lingyu || [];
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    reload() {
      this.getNewsAll(this.searchAll);
    },
  },
  created() {
    this.getNewsAll();
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
.partitem {
  font-size: 14px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 15px;
  > p {
    font-weight: bold;
  }
}
</style>
